package com.dmpp.mes.bean;

/**
 * Created by jyf on 2019/6/3.
 */

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(value = "ResponseData<T>")
public class ResponseData<T> {

    @ApiModelProperty(value = "code", name = "code")
    private String code;

    @ApiModelProperty(value = "msg", name = "msg")
    private String msg;

    @ApiModelProperty(value = "data", name = "data")
    private T data;

    // 构造方法
    public static ResponseData success() {
        return new ResponseData(RespEnum.SUCCESS.getCode(), RespEnum.SUCCESS.getMessage());
    }

    public static ResponseData fail() {
        return new ResponseData(RespEnum.ERROR.getCode(), RespEnum.ERROR.getMessage());
    }

    public ResponseData(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public ResponseData(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    // getter & setter
    public String getCode() {
        return code;
    }

    private void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public ResponseData() {
        super();
        this.code = RespEnum.SUCCESS.getCode();
        this.msg = RespEnum.SUCCESS.getMessage();
    }

    public int setCodeEnum(RespEnum codeEnum) {
        setCode(codeEnum.getCode());
        setMsg(codeEnum.getMessage());
        return 0;
    }
}

